package TestPackage;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author Martin Haulrich
 */
public class EmpPOS {

    Map<String, Integer> counts;

    public int diffSuf;

    public int totalSuf;

    public int wordsCount;

    public EmpPOS() {
    }

    public EmpPOS(List<String> words) {

        counts = new HashMap<String, Integer>();
        int t = 0;
        for (String w : words) {
            t++;
            if (counts.containsKey(w)) {
                counts.put(w, counts.get(w) + 1);
            } else {
                counts.put(w, 1);
            }


        }
        diffSuf = counts.size();
        //diffSuf = dw.size();

        totalSuf = t;

        wordsCount = words.size();
    //      System.err.println(counts);

    }

    public double getCount(String s) {

        Integer c = counts.get(s);
        if (c == null) {
            //           System.err.println("IMMPPP");
            return 0.0;
        }
//  System.err.println("    count: " + c);

        return (double) c;

    }


    public double getEstimate(String s) {
        //    System.err.println(s);
        if (s.isEmpty()) {
            return 0;
        }

        double c = (double) getCount(s);


        double e = Math.log10(c / ((double) wordsCount));
        //   System.err.println("    e: " + e);
        if (e > 0) {
            System.err.println("????????????????? " + s + " = " + e);
        }

        return e;
    }
}
